using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DAXweb;

namespace Parsifal
{
    public partial class FrmOption : Form
    {
        private ManageMixer mMixer = null;


        private bool isLoad = false;

        public FrmOption()
        {
            InitializeComponent();
        }

        internal  void  SetMixer(ManageMixer aMixer)
        {

            mMixer = aMixer;
        }


        public void FrmOption_Load(object sender, EventArgs e)
        {
            try
            {

                //set the max value for tracking
                tBarWaveIn.Maximum = mMixer.MAX_STEP;
                tSourceSTereo.Maximum = mMixer.MAX_STEP;
                tVMusicParlato.Maximum = mMixer.MAX_STEP;
                tVolumeMic.Maximum = mMixer.MAX_STEP;



                modeCombo.Click +=new EventHandler(modeCombo_Click);

                modeCombo.Items.Add("FILESOURCE");
                modeCombo.Items.Add("SOUNDCARD");

 #if _XP_
                string mode = ManageSettings.Instance.GetSettingValue("MODE");
                if (mode == "FILESOURCE")
                {
                    modeCombo.SelectedItem = "FILESOURCE";
                    
                }
                else if (mode == "SOUNDCARD")
                {
                    modeCombo.SelectedItem = "SOUNDCARD";
                }





                string valore = ManageSettings.Instance.GetSettingValue("V_P_MUSIC_MAX");
                if (valore != null)
                {
                    tBarWaveIn.Value = Convert.ToInt32(valore);
                    label6.Text = valore;
                }


                valore = ManageSettings.Instance.GetSettingValue("V_P_MUSIC_MIN");
                if (valore != null)
                {
                    tVMusicParlato.Value = Convert.ToInt32(valore);
                    label7.Text = valore;
                }

                valore = ManageSettings.Instance.GetSettingValue("V_P_MICROPHONE_MAX");
                if (valore != null)
                {
                    tVolumeMic.Value = Convert.ToInt32(valore);
                    label8.Text = valore;
                }

                valore = ManageSettings.Instance.GetSettingValue("FADE_DURING");
                if (valore != null)
                {
                    tDurata.Value = Convert.ToInt32(valore);
                    label9.Text = valore;
                }

                valore = ManageSettings.Instance.GetSettingValue("V_R_SMIX");
                if (valore != null)
                {
                    tSourceSTereo.Value = Convert.ToInt32(valore);
                    label10.Text = valore;
                }


               

                //auto volume
                try
                {

                    valore = ManageSettings.Instance.GetSettingValue("AUTO_VOLUME");
                    if (valore != null)
                    {
                        if (valore == "1")
                        {
                            chkAutoVolume.CheckState = CheckState.Checked;
                        }
                        else
                            chkAutoVolume.CheckState = CheckState.Unchecked;
                    }
                }
                catch (Exception err)
                {}



#endif

            }
            catch (Exception err)
            {
                
                throw err;
            }

        }

        private void modeCombo_Click(Object sender, EventArgs e)
        {
            isLoad = true;
        }

        private void modeCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
 #if _XP_
            if (isLoad)
            {
                if (modeCombo.SelectedIndex == 0)
                    ManageSettings.Instance.SetSettingsValue("MODE", "FILESOURCE");
                else if (modeCombo.SelectedIndex == 1)
                    ManageSettings.Instance.SetSettingsValue("MODE", "SOUNDCARD");

                label1.Visible = true;
                
             
            }
#endif
        }

        public void button1_Click(object sender, EventArgs e)
        {

            mMixer.SetMixerValue();
            

            //ManageSettings.Instance.WriteSettings();

            
        }

        public void tBarWaveIn_Scroll(object sender, EventArgs e)
        {
            ManageSettings.Instance.SetSettingsValue("V_P_MUSIC_MAX", 
                tBarWaveIn.Value.ToString());

            mMixer.VolumeMusic = tBarWaveIn.Value;

            label6.Text = tBarWaveIn.Value.ToString();
        }

        private void tVMusicParlato_Scroll(object sender, EventArgs e)
        {
            ManageSettings.Instance.SetSettingsValue("V_P_MUSIC_MIN",
                tVMusicParlato.Value.ToString());

            mMixer.VolumeMusicDuringLive = tVMusicParlato.Value;

            label7.Text = tVMusicParlato.Value.ToString();
        }

        private void tVolumeMic_Scroll(object sender, EventArgs e)
        {

            ManageSettings.Instance.SetSettingsValue("V_P_MICROPHONE_MAX",
               tVolumeMic.Value.ToString());

            mMixer.VolumeMicrophone = tVolumeMic.Value;

            label8.Text = tVolumeMic.Value.ToString();
        }

        private void tDurata_Scroll(object sender, EventArgs e)
        {
            ManageSettings.Instance.SetSettingsValue("FADE_DURING",
               tDurata.Value.ToString());

            mMixer.TimeDuringFading = tDurata.Value;

            label9.Text = tDurata.Value.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void tSourceSTereo_Scroll(object sender, EventArgs e)
        {
            ManageSettings.Instance.SetSettingsValue("V_R_SMIX",
              tSourceSTereo.Value.ToString());

            mMixer.VolumeSourceIn = tSourceSTereo.Value;

            label10.Text = tSourceSTereo.Value.ToString();
        }

        public void button3_Click(object sender, EventArgs e)
        {
            mMixer.SetMixerValue();


            ManageSettings.Instance.WriteSettings();

            this.Close();
        }

        private void chkAutoVolume_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAutoVolume.Checked)
            {
                mMixer.AutoVolume = 1;
                ManageSettings.Instance.SetSettingsValue("AUTO_VOLUME", "1");
            }
            else
            {
                mMixer.AutoVolume = 0;
                ManageSettings.Instance.SetSettingsValue("AUTO_VOLUME", "0");
            }

        }

        
    }
}